package com.assessment.web;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.assessment.dto.PerformanceInterviewDTO;
import com.assessment.entity.PerformanceInterview;
import com.assessment.service.IPerformanceInterviewService;
import com.common.util.AJAXResultMessage;
import com.common.util.ExtjsPageable;
import com.syslog.aop.SystemServiceLog;

@Controller
@RequestMapping(value="/performanceInterview")
public class PerformanceInterviewController
{
	@Autowired
	private IPerformanceInterviewService performanceInterviewService;
	
	@SystemServiceLog("新建或修改面谈记录")
	@RequestMapping(value="/saveOrUpdate")
	public @ResponseBody AJAXResultMessage saveOrUpdate(PerformanceInterviewDTO performanceInterviewDTO) 
	{
		try {
			performanceInterviewService.saveOrUpdate(performanceInterviewDTO);
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
	}
	
	@SystemServiceLog("批量删除面谈记录")
	@RequestMapping(value = "/deletePerformanceInterviews")
    public @ResponseBody AJAXResultMessage delete(Long[] ids) {
    	try {
    		List<Long> idlists=Arrays.asList(ids);
    		if(null!=idlists) {
    			performanceInterviewService.delete(idlists);
    		}    		
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
    }
	
	@SystemServiceLog("删除面谈记录")
	@RequestMapping(value = "/delete")
    public @ResponseBody AJAXResultMessage delete(Long id) {
    	try {
    		performanceInterviewService.delete(id);
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
    }
//	@RequestMapping("/findOne")
//	public @ResponseBody PerformanceInterviewDTO findOne(Long id) {
//		return performanceInterviewService.findOne(id);
//	}
	
	@SystemServiceLog("查找面谈记录")
	@RequestMapping("/findPage")
	public @ResponseBody Page<PerformanceInterviewDTO> findAll(PerformanceInterviewDTO performanceInterviewDTO,ExtjsPageable pageable) 
	{
		Page<PerformanceInterviewDTO> page = new PageImpl<PerformanceInterviewDTO>(new ArrayList<PerformanceInterviewDTO>(), pageable.getPageable(), 0);

		page =performanceInterviewService.findAll(PerformanceInterviewDTO.getSpecification(performanceInterviewDTO), pageable.getPageable());		
		return page;
	}
	
}
